<template>
  <div class="view-fill">
    <div v-if="!modifyInfo.visible" class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        title="计量检定任务详情"
        @returnBack="returnBack"
      >
        <template v-slot:full-button>
          <el-button
            v-if="
              $permission('assetInstrumentsPlan:entry') &&
              infoList.data.status === 1
            "
            @click="entry"
            >录入检定结果</el-button
          >
          <el-button
            v-if="
              $permission('assetInstrumentsPlan:cancel') &&
              infoList.data.status === 1
            "
            @click="cancel"
            >取消任务</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-body">
            <BasicInformation :info="infoList">
              <template v-slot:basic-filePathList>
                <EleGallery
                  v-if="infoList.data.filePathList"
                  :lazy="true"
                  :size="150"
                  :source="infoList.data.filePathList"
                  title="附件"
                />
                <span v-else>-</span>
              </template>
            </BasicInformation>
          </div>
        </div>
      </NewFullScreen>
    </div>
    <asset-instruments-plan-modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :plan-id="modifyInfo.planId"
      @returnModify="getMain"
    />
  </div>
</template>

<script setup name="AssetInstrumentsPlanDetail">
import EleGallery from '@/components/UploadImgNew/eleGallery'
import AssetInstrumentsPlanModify from './modify'
import {
  getMeasuringVerificationTaskById,
  cancelMeasuringVerificationTask,
} from '@/api/quality.js'
const props = defineProps(['visible', 'orderId'])
const { proxy } = getCurrentInstance()
const infoList = ref({
  data: {
    filePathList: '',
  },
  fieldList: [
    {
      label: '任务编号',
      value: 'orderNo',
      type: 'text',
    },
    {
      label: '器具标准名称',
      value: 'commonName',
      type: 'text',
    },
    { label: '器具编码', value: 'code', type: 'text' },
    { label: '资产名称', value: 'assetName', type: 'text' },
    { label: '资产卡片号', value: 'assetCode', type: 'text' },
    { label: '规格', value: 'standard', type: 'text' },
    { label: '品牌', value: 'trademark', type: 'text' },
    {
      label: '是否强检',
      value: 'mandatoryTestValue',
      type: 'text',
    },
    { label: '检定周期(月)', value: 'verificationPeriod', type: 'text' },
    { label: '上次检定日期', value: 'verificationDate', type: 'text' },
    {
      label: '上次检定证书编号',
      value: 'verificationCertificateNumber',
      type: 'text',
    },
    { label: '检定单位', value: 'verificationUnit', type: 'text' },
    { label: '计划检定日期', value: 'validityDate', type: 'text' },
    { label: '状态', value: 'statusValue', type: 'text' },
  ],
})
const modifyInfo = ref({
  visible: false,
  planId: '',
  title: '',
})
const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    proxy.$emit('update:visible', val) // 更新父组件visible
  },
})
//录入
function entry() {
  modifyInfo.value.planId = infoList.value.data.id
  modifyInfo.value.orderId = infoList.value.data.id
  modifyInfo.value.title = '录入检定结果'
  modifyInfo.value.visible = true
}
function cancel() {
  cancelMeasuringVerificationTask([infoList.value.data.id]).then((resp) => {
    if (resp && resp.success) {
      getMain()
    }
  })
}
function getMain() {
  getMeasuringVerificationTaskById(props.orderId).then((res) => {
    if (res.success) {
      infoList.value.data = res.data
    }
  })
}
function returnBack() {
  proxy.$emit('returnBack', false)
}

getMain()
</script>

<style scoped></style>
